<html>
<head><meta charset="utf-8"><title>removing () locals · t-compiler/wg-mir-opt · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/index.html">t-compiler/wg-mir-opt</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html">removing () locals</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="190601231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190601231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190601231">(Mar 14 2020 at 15:20)</a>:</h4>
<p>Are there any plans which would get rid of all the <code>()</code> locals generated? I see they survive until LLVM IR which isn't great.</p>



<a name="190601247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190601247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190601247">(Mar 14 2020 at 15:21)</a>:</h4>
<p>Yes, but it's blocked on <a href="https://github.com/rust-lang/rust/issues/67191" target="_blank" title="https://github.com/rust-lang/rust/issues/67191">#67191</a> because otherwise we start not evaluating constants with <code>()</code> value even if the constant would error if evaluated</p>



<a name="190601285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190601285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190601285">(Mar 14 2020 at 15:22)</a>:</h4>
<p>We've actually had this optimization but had to roll back out of that reason.</p>



<a name="190601829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190601829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190601829">(Mar 14 2020 at 15:40)</a>:</h4>
<p>Can't we just keep such constant assignments?  What optimization was that?</p>



<a name="190601924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190601924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190601924">(Mar 14 2020 at 15:42)</a>:</h4>
<p>That's what we do: <a href="https://github.com/rust-lang/rust/blob/42ce9b4e9054d63c8f352f994e2d5dae7d04130f/src/librustc_mir/transform/simplify.rs#L375" target="_blank" title="https://github.com/rust-lang/rust/blob/42ce9b4e9054d63c8f352f994e2d5dae7d04130f/src/librustc_mir/transform/simplify.rs#L375">https://github.com/rust-lang/rust/blob/42ce9b4e9054d63c8f352f994e2d5dae7d04130f/src/librustc_mir/transform/simplify.rs#L375</a></p>



<a name="190602099"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190602099" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190602099">(Mar 14 2020 at 15:48)</a>:</h4>
<p><code>SimplifyLocals</code> doesn't remove all <code>()</code> locals though. Some are assigned by calls and those stick around. Maybe we'd want something that could purge all ZST locals?</p>



<a name="190602383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190602383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190602383">(Mar 14 2020 at 15:57)</a>:</h4>
<p>Hmm... we could replace all <code>Rvalue::Ref</code> to <code>()</code> locals by a constant that is essentially <code>ptr::dangling()</code>. But I don't see how we can get rid of function return places. They need to have a return place</p>



<a name="190602457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190602457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190602457">(Mar 14 2020 at 15:59)</a>:</h4>
<p>We could just allow functions to return without a return place. So <code>_3 = const print() -&gt; [return: bb2, unwind: bb4]</code> would be just <code>const print() -&gt; [return: bb2, unwind: bb4]</code>. It would make MIR output more readable too =P</p>



<a name="190602526"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190602526" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190602526">(Mar 14 2020 at 16:00)</a>:</h4>
<p>I don't think borrowing <code>()</code> is very common though, we could perhaps keep that. I think every non-returning call making it's own <code>()</code> local is the problematic case.</p>



<a name="190602658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190602658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190602658">(Mar 14 2020 at 16:05)</a>:</h4>
<p>Maybe just removing <code>StorageDead/Live</code> for <code>()</code> locals would help with performance</p>



<a name="190604138"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190604138" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190604138">(Mar 14 2020 at 16:46)</a>:</h4>
<p>I wonder if that would interfere with anything <span class="user-mention" data-user-id="120791">@RalfJ</span> wants to rely on <code>Storage{Live,Dead}</code> for</p>



<a name="190604155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190604155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190604155">(Mar 14 2020 at 16:46)</a>:</h4>
<p>but I generally agree we should strive for less noisy MIR</p>



<a name="190604499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190604499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190604499">(Mar 14 2020 at 16:56)</a>:</h4>
<p>Miri shouldn't run on optimized MIR at least (if you want to catch UB)</p>



<a name="190606863"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190606863" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190606863">(Mar 14 2020 at 17:58)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> ^^ impedance mismatch :P</p>



<a name="190609200"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190609200" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190609200">(Mar 14 2020 at 19:05)</a>:</h4>
<p>we can always overload the <code>optimized_mir</code> query if we want to (or set the mir opt level low)</p>



<a name="190609420"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190609420" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190609420">(Mar 14 2020 at 19:10)</a>:</h4>
<p><span class="user-mention" data-user-id="124288">@oli</span> Overloading the <code>optimized_mir</code> query is hard, as <code>rustc_mir</code> doesn't export any mir passes. Some mir passes are mandatory though, like the generator transform and borrowck.</p>



<a name="190609439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190609439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190609439">(Mar 14 2020 at 19:11)</a>:</h4>
<p>true, but at mir-opt-level=0 we should only be doing strictly necessary things</p>



<a name="190640655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190640655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190640655">(Mar 15 2020 at 10:23)</a>:</h4>
<p><span class="user-mention silent" data-user-id="119009">eddyb</span> <a href="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20().20locals/near/190604138" title="#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/removing.20().20locals/near/190604138">said</a>:</p>
<blockquote>
<p>I wonder if that would interfere with anything <span class="user-mention silent" data-user-id="120791">RalfJ</span> wants to rely on <code>Storage{Live,Dead}</code> for</p>
</blockquote>
<p>I am not relying on <code>StorageLive/Dead</code> for anything, really. We are just <em>interpreting</em> them in Miri, giving them concrete meaning, and I am trying to align dataflow analyses assumptions with the meaning they are given there.</p>



<a name="190640703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190640703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190640703">(Mar 15 2020 at 10:24)</a>:</h4>
<p>I assume with <code>mir-opt-level=0</code>, none of these optimizations happen? That would be good for Miri's ability to still check that the initially created MIR makes sense.</p>



<a name="190732741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/189540-t-compiler/wg-mir-opt/topic/removing%20%28%29%20locals/near/190732741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Wesley Wiser <a href="https://rust-lang.github.io/zulip_archive/stream/189540-t-compiler/wg-mir-opt/topic/removing.20().20locals.html#190732741">(Mar 16 2020 at 14:52)</a>:</h4>
<p>Yes, that definitely should be the case.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>